package guestbook.controlador;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;


import javax.servlet.http.*;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;


import guestbook.dao.SaludoDAO;
import guestbook.dao.SaludoDAOImplementation;
import guestbook.persistencia.Saludo;

public class CrearMensajeServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(CrearMensajeServlet.class.getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        String content = req.getParameter("content");
        Date date = new Date();
        Saludo greeting = new Saludo(user, content, date);
        
        System.out.println("antes id="+greeting.getId());
        SaludoDAO saludoDAO = new SaludoDAOImplementation();
        saludoDAO.insert(greeting);
        saludoDAO.cerrar();
        
        System.out.println("despues id="+greeting.getId());

        resp.sendRedirect("guestbook_ver_mensajes.jsp");
    }
}